/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Agent;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Alternative;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Expectation;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.KaosGoalModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Expectation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.ExpectationImpl#getAgent <em>Agent</em>}</li>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.ExpectationImpl#getAlternatives <em>Alternatives</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ExpectationImpl extends GoalModelElementImpl implements Expectation {
	/**
	 * The cached value of the '{@link #getAgent() <em>Agent</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAgent()
	 * @generated
	 * @ordered
	 */
	protected Agent agent;
	/**
	 * The cached value of the '{@link #getAlternatives() <em>Alternatives</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAlternatives()
	 * @generated
	 * @ordered
	 */
	protected EList alternatives;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ExpectationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return KaosGoalModelPackage.Literals.EXPECTATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Agent getAgent() {
		if (agent != null && agent.eIsProxy()) {
			InternalEObject oldAgent = (InternalEObject)agent;
			agent = (Agent)eResolveProxy(oldAgent);
			if (agent != oldAgent) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, KaosGoalModelPackage.EXPECTATION__AGENT, oldAgent, agent));
			}
		}
		return agent;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Agent basicGetAgent() {
		return agent;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAgent(Agent newAgent, NotificationChain msgs) {
		Agent oldAgent = agent;
		agent = newAgent;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, KaosGoalModelPackage.EXPECTATION__AGENT, oldAgent, newAgent);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAgent(Agent newAgent) {
		if (newAgent != agent) {
			NotificationChain msgs = null;
			if (agent != null)
				msgs = ((InternalEObject)agent).eInverseRemove(this, KaosGoalModelPackage.AGENT__EXPECTATION, Agent.class, msgs);
			if (newAgent != null)
				msgs = ((InternalEObject)newAgent).eInverseAdd(this, KaosGoalModelPackage.AGENT__EXPECTATION, Agent.class, msgs);
			msgs = basicSetAgent(newAgent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, KaosGoalModelPackage.EXPECTATION__AGENT, newAgent, newAgent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getAlternatives() {
		if (alternatives == null) {
			alternatives = new EObjectWithInverseResolvingEList.ManyInverse(Alternative.class, this, KaosGoalModelPackage.EXPECTATION__ALTERNATIVES, KaosGoalModelPackage.ALTERNATIVE__EXPECTATION);
		}
		return alternatives;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				if (agent != null)
					msgs = ((InternalEObject)agent).eInverseRemove(this, KaosGoalModelPackage.AGENT__EXPECTATION, Agent.class, msgs);
				return basicSetAgent((Agent)otherEnd, msgs);
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				return ((InternalEList)getAlternatives()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				return basicSetAgent(null, msgs);
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				return ((InternalEList)getAlternatives()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				if (resolve) return getAgent();
				return basicGetAgent();
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				return getAlternatives();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				setAgent((Agent)newValue);
				return;
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				getAlternatives().clear();
				getAlternatives().addAll((Collection)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				setAgent((Agent)null);
				return;
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				getAlternatives().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case KaosGoalModelPackage.EXPECTATION__AGENT:
				return agent != null;
			case KaosGoalModelPackage.EXPECTATION__ALTERNATIVES:
				return alternatives != null && !alternatives.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //ExpectationImpl
